package com.d3works.apps.hr.db.repo;

import com.d3works.apps.base.db.repo.UserBaseRepository;
import com.d3works.apps.hr.db.Employee;
import com.d3works.auth.db.User;
import com.d3works.inject.Beans;

public class UserHRRepository extends UserBaseRepository {

  @Override
  public void remove(User user) {
    if (user.getEmployee() != null) {
      EmployeeHRRepository employeeRepo = Beans.get(EmployeeHRRepository.class);
      Employee employee = employeeRepo.find(user.getEmployee().getId());
      if (employee != null) {
        employee.setUser(null);
        employeeRepo.save(employee);
      }
    }
    super.remove(user);
  }
}
